<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:inline="javascript">
        $(function () {
            $.get("/plays/clubs",function (data) {
                for (club of data){
                    if (club.cid == [[${cid}]]){
                        $("select").append("<option value='"+club.cid+"' selected>"+club.cname+"</option>")
                    }else{
                        $("select").append("<option value='"+club.cid+"'>"+club.cname+"</option>")
                    }
                }
            },"json")
        })
        $(function () {
            $("form").submit(function () {
                if ($("[name=pname]").val()==""){
                    alert("球员姓名不能为空")
                    return false;
                }else if ($("[name=birthday]").val()==""){
                    alert("日期不能为空")
                    return false;
                }else if ($("[name=height]").val()==""){
                    alert("身高不能为空")
                    return false;
                }else if ($("[name=weight]").val()==""){
                    alert("体重不能为空")
                    return false;
                } else if ($("[name=cid]").val()==""){
                    alert("请选择所属球队")
                    return false;
                }

                var rq = /^\d{4}-\d{2}-\d{2}$/
                var re = /^\d+$/
                if (!rq.test($("[name=birthday]").val())){
                    alert("日期格式错误");
                    return false;
                }else if (!re.test($("[name=height]").val())){
                    alert("身高只能为数字")
                    return false;
                }else if (!re.test($("[name=weight]").val())){
                    alert("体重只能为数字")
                    return false;
                }

            })
        })

    </script>
</head>
<body>
<div style="margin: 0px auto;width: 520px">
    <h1 style="text-align: center">添加球员信息</h1>
    <form action="/plays/insert" method="post">
        <table width="520px">
            <tr>
                <td>球员姓名：</td>
                <td><input type="text" name="pname"></td>
            </tr>
            <tr>
                <td>出生日期：</td>
                <td><input type="text" name="birthday"></td>
            </tr>
            <tr>
                <td>球员身高：</td>
                <td><input type="text" name="height"></td>
            </tr>
            <tr>
                <td>球员体重：</td>
                <td><input type="text" name="weight"></td>
            </tr>
            <tr>
                <td>球员位置：</td>
                <td>
                    <input type="radio" name="position" value="控球后卫" checked>控球后卫
                    <input type="radio" name="position" value="得分后卫">得分后卫
                    <input type="radio" name="position" value="小前锋">小前锋
                    <input type="radio" name="position" value="中锋">中锋
                </td>
            </tr>
            <tr>
                <td>所属球队：</td>
                <td>
                    <select name="cid">
                        <option value="">--请选择--</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td>相关操作：</td>
                <td><input type="submit" value="新增">
                    <a href="/plays">
                        <input type="button" value="返回">
                    </a>
                </td>
            </tr>
        </table>
    </form>
</div>


</body>
</html>